#pragma once

#include "StdAfx.h"
#include "Afxmt.h"

#define MAX_HEAD_SIZE	16
#define MAX_LEVEL_SIZE	8
#define MAX_BODY_SIZE	256
#define MAX_NODE		50

typedef enum _Log_Level_
{
	LOG_UNKNOWN,
	LOG_ERROR,
	LOG_WARNING,
	LOG_INFO,	
}LOG_LEVEL;


class CLog
{
public:
	CLog(void);
	CLog(LPTSTR szHead, UINT nHeadLen, LOG_LEVEL level, LPTSTR szBody, UINT nBodyLen);
	~CLog(void);
private:
//public:
	LOG_LEVEL	m_level;
	LPTSTR		m_szHead;
	LPTSTR		m_szBody;
public:
	void GetLogInfo(LPTSTR info, UINT nMaxLen);
	CLog& operator= (const CLog& log);
};

class CLogNode
{
public:
	CLogNode(void);
	CLogNode(CLog& log);
	~CLogNode(void);
public:
	CLog m_log;
public:
	CLogNode* m_pNext;
};

class CLogFile
{
public:
	CLogFile(void);
	CLogFile(LPCTSTR lpszPath);
	~CLogFile(void);
private:	
	UINT m_nNodeCount;
	CFile* m_hFile;
	BOOL m_bSave;
	LPTSTR m_szLogBuffer;
	BOOL m_bBufUpdated;
	CMutex m_mutex;

public:
	CLogNode* m_pHead;
	BOOL AddLogNode(CLogNode* pAddNode);
	BOOL LogOut(CLogNode* pNode);
	void EnableLog(void);
	void DisableLog(void);
	BOOL SetLogFilePath(LPCTSTR lpszPath);
	LPTSTR GetLogBuffer(BOOL &bUpdated);
};
